#include <iostream>
using namespace std;
typedef int* pInt;
typedef class Node
{
public:
	int val;
	Node *left;
	Node *right;
	Node(){val = 0; left = right = NULL;}
} *BinTree;
void createTree(int *pos, int *in, int n, Node* &root)
{
	if(n > 0)
	{
		int temp = pos[n-1];
		int i;
		root = new Node();
		root->val = temp;
		for(i = 0; i < n; i++)
			if(in[i] == temp)
				break;
		createTree(&pos[0], &in[0], i, root->left);
		createTree(&pos[i], &in[i + 1], n - i - 1, root->right);
	}
}
void printLevel(Node *root, int* &a)
{
	a = new int[1010];
	int c = 0;
	int countt = 0, countf = 0;
	Node *pointer = root;
	Node *arr[1010];
	if(pointer != NULL)
		arr[countt++] = pointer;
	while(countf < countt)
	{
		pointer = arr[countf++];
		if(pointer->left != NULL)
			arr[countt++] = pointer->left;
		if(pointer->right != NULL)
			arr[countt++] = pointer->right;
		a[c++] = pointer->val;
	}
}
int main()
{
	int n, i;
	cin >> n;
	int pre[1010];
	int in[1010];
	for(i = 0; i < n; i++)
		cin >> pre[i];
	for(i = 0; i < n; i++)
		cin >> in[i];
	Node *root = NULL;
	createTree(pre, in, n, root);
	int *arr;
	printLevel(root, arr);
	for(i = 0; i < n - 1; i++)
		cout << arr[i] << " ";
	if(n > 0)
		cout <<arr[n - 1];
	return 0;
}
